﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SUT = Admx_Generator;

namespace Tests_Admx_Generator
{
    /// <summary>
    /// Description résumée pour Test_Reference
    /// </summary>
    [TestClass]
    public class Test_Reference
    {
        [TestClass]
        public class Constructor_Should
        {
            [TestMethod]
            public void ProperlyInitializeProperties_WhenCalled()
            {
                // Arrange
                SUT.Reference reference1;
                SUT.Reference reference2;
                
                // Act
                reference1 = new SUT.Reference("PstBackup2013", "ParentCategory");
                reference2 = new SUT.Reference("PstBackup2013:ParentCategory");

                // Assert
                Assert.AreEqual(reference1.NamespacePrefix, "PstBackup2013");
                Assert.AreEqual(reference1.ReferencedName, "ParentCategory");
                Assert.AreEqual(reference2.NamespacePrefix, "PstBackup2013");
                Assert.AreEqual(reference2.ReferencedName, "ParentCategory");
            }
        }

        [TestClass]
        public class Equal_Should
        {
            [TestMethod]
            public void ReturnTrue_WhenComparingIdenticalReferences()
            {
                // Arrange
                SUT.Reference reference1;
                SUT.Reference reference2;
                SUT.Reference reference3;

                // Act
                reference1 = new SUT.Reference("PstBackup2013", "ParentCategory");
                reference2 = new SUT.Reference("PstBackup2013", "ParentCategory");
                reference3 = new SUT.Reference("PstBackup2013:ParentCategory");

                // Assert
                Assert.IsTrue(reference1.Equals(reference2));
                Assert.IsTrue(reference1.Equals(reference3));
            }

            [TestMethod]
            public void ReturnFalse_WhenComparingWithNullParameter()
            {
                // Arrange
                SUT.Reference reference1;
                SUT.Reference reference2;

                // Act
                reference1 = new SUT.Reference("PstBackup2013", "ParentCategory");
                reference2 = null;

                // Assert
                Assert.IsFalse(reference1.Equals(reference2));
            }

            [TestMethod]
            public void ReturnFalse_WhenComparingTwoDifferentsReferences()
            {
                // Arrange
                SUT.Reference reference1;
                SUT.Reference reference2;
                SUT.Reference reference3;
                SUT.Reference reference4;

                // Act
                reference1 = new SUT.Reference("PstBackup2013", "ParentCategory");
                reference2 = new SUT.Reference("PstBackup2016", "ParentCategory");
                reference3 = new SUT.Reference("PstBackup2013", "ParentCategory2");
                reference4 = new SUT.Reference("PstBackup2013:ParentCategory2");

                // Assert
                Assert.IsFalse(reference1.Equals(reference2));
                Assert.IsFalse(reference1.Equals(reference3));
                Assert.IsFalse(reference1.Equals(reference4));
            }
        }

        [TestClass]
        public class ToString_Should
        {
            [TestMethod]
            public void ReturnWellFormattedString_WhenCalled()
            {
                // Arrange
                SUT.Reference reference1 = new SUT.Reference("PstBackup2013", "ParentCategory");
                SUT.Reference reference2 = new SUT.Reference("PstBackup2013:ParentCategory");
                SUT.Reference reference3 = new SUT.Reference(String.Empty, "ParentCategory");

                // Assert
                Assert.AreEqual(reference1.ToString(), "PstBackup2013:ParentCategory");
                Assert.AreEqual(reference2.ToString(), "PstBackup2013:ParentCategory");
                Assert.AreEqual(reference3.ToString(), "ParentCategory");
            }
        }
    }
}
